/**
 * @Author       : Hejh(3010733382@qq.com)
 * @Version      : V1.0
 * @Date         : 2024-01-15 18:00:14
 * @Description  : 用户-部门的修改操作路由
 */
const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const userDepValidate = require('@/middlewares/validateMiddlewares/userDepValidate')
const userLog = require('@/middlewares/logMiddlewares/userLog')
const checkUserUpdate = require('@/middlewares/checkUpdateMiddlewares/userUpdate')
const { commonSuccessLog } = require('@/middlewares/logMiddlewares/commonLog')
const { verifyAuth } = require('@/middlewares/authMiddlewares/verifyAuth')
const userDepController = require('@/controller/userDepController')
const userCheckUpdate = require('@/middlewares/checkUpdateMiddlewares/userUpdate')

const router = new Router()

/**
 * 部门内新增用户
 */
router.post(
  '/create',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.createUserToDepValidate,
  userLog.createUserLog,
  userDepController.createUserToDep
)

/**
 * 部门内更新用户
 */
router.post(
  '/update',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.updateUserToDepValidate,
  userCheckUpdate.UserDepSingerUpdateCheck,
  userLog.updateUserLog,
  userDepController.updateUserToDep
)

/**
 * 部门内用户迁移到其他部门
 */
router.put(
  '/move',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.moveUserToDepValidate,
  userLog.moveToDepLog,
  userDepController.moveUserToDep
)

/**
 * 添加已有用户到部门接口
 */
router.post(
  '/copy',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.copyUserToDepValidate,
  userLog.copyToDepLog,
  userDepController.copyUserToDep
)

/**
 * 部门中移除某个用户
 */

router.delete(
  '/delete',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.delUserDepsValidate,
  checkUserUpdate.delUserDepsSave,
  commonSuccessLog,
  userDepController.delUserDeps
)

/**
 * 设置部门内部分成员容量大小
 */
router.put(
  '/setSizeMax',
  verifyToken(),
  verifyAuth(['admin.member.edit']),
  userDepValidate.setUserDepsSizeMaxValidate,
  userLog.setUserDepsSizeMaxLog,
  userDepController.setUserDepsSizeMax
)
module.exports = router
